home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap5 / 5_1 / parse_c / dict.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.3 KB  |  67 lines

  1.  
  2. #ifndef DICTIONARY_H
  3. #define DICTIONARY_H
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. #define DEF_CAPACITY 17
  9. #define GROW_PERCENTAGE 0.90
  10. #define GROWTH_RATE 2
  11.  
  12. typedef struct _dict *Dictionary;
  13. typedef struct _dictState DictState;
  14.  
  15. struct listnode
  16. {
  17.  
  18.     struct listnode *next;
  19.     char * key;
  20.     void * value;
  21.  
  22. };
  23.  
  24. struct _dict
  25. {
  26.     struct listnode **hashtable;
  27.     unsigned int size;
  28.     unsigned int used;
  29. };
  30.  
  31. struct _dictState
  32. {
  33.     unsigned int curIndex;
  34.     struct listnode *curNode;
  35.     Dictionary dict;
  36.     unsigned int bumpedCurNode;/* Used when removing nodes */
  37. };
  38.  
  39. Dictionary dict_alloc();
  40.  
  41. void dict_free(Dictionary aDict);/* Doesnt free the values */
  42.  
  43. /* Frees the values also, using the function freer */
  44. void dict_freeWithData(Dictionary aDict,void(*freer)());
  45.  
  46. int dict_isKey(Dictionary aDict, const char *aStr);
  47.  
  48. /* Set the value and return the old one, if it exists, copies the key */
  49. void * dict_setValueForKey(Dictionary aDict, const char *aKey, void *theValue);
  50.  
  51. /* Returns 0 if no value */
  52. void * dict_valueForKey(Dictionary aDict, const char *theKey);
  53.  
  54. /* Returns the value, and frees the key */
  55.  
  56. void * dict_orphanValueForKey(Dictionary aDict, const char *theKey);
  57.  
  58. /* Convience function to print the dictionary to std out */
  59.  
  60. void dict_printToStdout(Dictionary theDict);
  61.  
  62. DictState dict_initState(Dictionary aDict);
  63.  
  64. int dict_nextState(DictState *aState);
  65.  
  66. #endif
  67.